<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>展会报表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
    <style>
        .content .select2 {
            margin-bottom: 10px !important;
        }

        .content .area {
            display: none;
            background-color: #F4F5F5;
        }

        .content .area td {
            border-style: dashed;
        }

        .content .area td.region {
            font-weight: 100;
        }

        .content td.region {
            color: #489EF1;;
            cursor: pointer;
            text-align: left;
            font-weight: bold;
        }

        .content td span.empty {
            color: #cbcbcd;
        }

        .content .total td {
            font-weight: bold;
        }

    </style>
</head>
<body>
<section class="content">
    <h3 style="text-align: center"><span></span>展会汇总表</h3>
    <div class="exhibition-select" style="width: 300px;float: left">
        <select class="form-control select2">
            <option data-id="">选择展会</option>
        </select>
    </div>
    <a class="btn oaBtn btn-sm out-file" style="float:right;width: 80px;margin-left: 10px;" href="#">导出</a>
    <a class="btn oaBtn btn-sm cusInfo" style="float:right;width: 80px" href="#">客户明细</a>
    <!--<input type="button" value="导出" style="float: right" class="btn oaBtn btn-sm ">-->
    <table class="table table-hover table-bordered text-center">
        <thead>
        <tr>
            <th rowspan="2" style="width: 20%">大区</th>
            <th rowspan="2" style="width: 10%">大区经理</th>
            <th colspan="2" style="width: 25%">客户数量</th>
            <th colspan="5">定金情况</th>
        </tr>
        <tr>
            <th style="width: 10%">目标</th>
            <th style="width: 10%">参会人数</th>
            <th style="width: 10%">目标</th>
            <th style="width: 10%">已交</th>
            <th style="width: 10%">肯定交</th>
            <th style="width: 10%">不确定</th>
            <th style="width: 10%">不交</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</section>
</body>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/plugins/select2/select2.full.min.js"></script>
<script type="application/javascript">
    var loginUser = getCurrentUser();
    var exhibitionId = "";
    var exhibitionCreateUserId = "";

    $(".out-file").on("click", function () {
        location.href = server.ip + "/exhibition/outFile.json?userId=" + exhibitionCreateUserId + "&exhibitionId=" + $(".select2 option:selected").attr("data-id") + "&key=";
    });

    $(".cusInfo").on("click", function () {
        location.href = "customInfo.html?userId=" + loginUser.id + "&exhibitionId=" + exhibitionId;
    });

    $.wyui.postMethod(
        urlConfig.crm.exhibition.getExhibitionIdByUserId,
        {userId: loginUser.id},
        function (data) {
            exhibitionId = data[0].exhibitionId;
            exhibitionCreateUserId = data[0].CREATE_USER_ID;
            $(".content h3 span").html(data[0].EXHIBITION_DATE + " " + data[0].NAME);
        }, true);

    $(".table").on("click", ".region", function () {
        var thisTr = $(this).parent("tr");
        if (thisTr.attr("class") == "area") {
            var userId = $(this).attr("data-user-id");
            userId = userId == "" ? "xxxxxxxxxxx" : userId;
            location.href = "customInfo.html?userId=" + userId + "&exhibitionId=" + exhibitionId;
            return false;
        }
        while (true) {
            var nextTr = thisTr.next();
            if (nextTr.attr("class") == undefined || nextTr.attr("class") == "total")
                break;
            else {
                $(nextTr).toggle();
                thisTr = nextTr;
            }
        }
    });

    $(".select2").on("change", function () {
        var selected = $(this).find("option:selected");
        var dataId = selected.attr("data-id");
        exhibitionCreateUserId = selected.attr("data-user-id");
        exhibitionId = dataId;
        if (dataId != "") {
            $(".content h3 span").html(selected.html());
            initReprot(dataId);
        }
    });

    $.wyui.postMethod(
        urlConfig.crm.exhibition.getExhibitionListByCompany,
        {companyId: loginUser.companyId},
        function (data) {
            var recentTime = true;
            for (var i = 0; i < data.length; i++) {
                var exhibitionDate = data[i].EXHIBITION_DATE;
                if (new Date(exhibitionDate) > new Date() && recentTime) {
                    recentTime = false;
                    exhibitionId = data[i].ID;
                    exhibitionCreateUserId = data[i].CREATE_USER_ID;
                    if ("大区经理,区域支持,大客户总监".indexOf(loginUser.roleName)>-1)
                        exhibitionCreateUserId = loginUser.id;
                    $(".content h3 span").html(data[i].EXHIBITION_DATE + " " + data[0].NAME);
                    $(".exhibition-select select").append("<option selected data-id='" + data[i].ID + "' data-user-id='" + data[i].CREATE_USER_ID + "'>" + data[i].EXHIBITION_DATE + " " + data[i].NAME + "</option>");
                } else
                    $(".exhibition-select select").append("<option  data-id='" + data[i].ID + "' data-user-id='" + data[i].CREATE_USER_ID + "'>" + data[i].EXHIBITION_DATE + " " + data[i].NAME + "</option>");
            }
        }, true);

    initReprot = function (exhibitionId) {
        $.wyui.postMethod(
            urlConfig.crm.exhibition.getReportData,
            {userId: exhibitionCreateUserId, exhibitionId: exhibitionId},
            function (data) {
                var str = new Array();

                var totalData = {
                    "customNum": 0,
                    "participationNum": 0,
                    "depositNum": 0,
                    "deposit1": 0,
                    "deposit2": 0,
                    "deposit3": 0,
                    "deposit4": 0
                }

                for (var i = 0; i < data.length; i++) {
                    var reportData = data[i];
                    if (reportData.PARENTID == 0) {
                        str.push("<tr>");
                        totalData.customNum = Number(totalData.customNum) + Number(reportData.customNum);
                        totalData.participationNum = Number(totalData.participationNum) + Number(reportData.participationNum);
                        totalData.depositNum = Number(totalData.depositNum) + Number(reportData.depositNum);
                        totalData.deposit1 = Number(totalData.deposit1) + Number(reportData.deposit1);
                        totalData.deposit2 = Number(totalData.deposit2) + Number(reportData.deposit2);
                        totalData.deposit3 = Number(totalData.deposit3) + Number(reportData.deposit3);
                        totalData.deposit4 = Number(totalData.deposit4) + Number(reportData.deposit4);
                    } else
                        str.push("<tr class='area'>");
                    str.push("  <td class='region' data-user-id='" + reportData.userId + "'>" + reportData.NAME + "</td>");
                    str.push("  <td>" + (reportData.userName == "" ? "<span class='empty'>空缺</span>" : reportData.userName) + "</td>");
                    str.push("  <td>" + (reportData.customNum == 0 ? "" : reportData.customNum) + "</td>");
                    str.push("  <td>" + (reportData.participationNum == 0 ? "" : reportData.participationNum) + "</td>");
                    str.push("  <td>" + (reportData.depositNum == 0 ? "" : reportData.depositNum) + "</td>");
                    str.push("  <td>" + (reportData.deposit1 == 0 ? "" : reportData.deposit1) + "</td>");
                    str.push("  <td>" + (reportData.deposit2 == 0 ? "" : reportData.deposit2) + "</td>");
                    str.push("  <td>" + (reportData.deposit3 == 0 ? "" : reportData.deposit3) + "</td>");
                    str.push("  <td>" + (reportData.deposit4 == 0 ? "" : reportData.deposit4) + "</td>");
                    str.push("</tr>");
                }
                str.push("<tr class='total'>");
                str.push("  <td colspan='2'>合计</td>");
                str.push("  <td>" + (totalData.customNum == 0 ? "" : totalData.customNum) + "</td>");
                str.push("  <td>" + (totalData.participationNum == 0 ? "" : totalData.participationNum) + "</td>");
                str.push("  <td>" + (totalData.depositNum == 0 ? "" : totalData.depositNum) + "</td>");
                str.push("  <td>" + (totalData.deposit1 == 0 ? "" : totalData.deposit1) + "</td>");
                str.push("  <td>" + (totalData.deposit2 == 0 ? "" : totalData.deposit2) + "</td>");
                str.push("  <td>" + (totalData.deposit3 == 0 ? "" : totalData.deposit3) + "</td>");
                str.push("  <td>" + (totalData.deposit4 == 0 ? "" : totalData.deposit4) + "</td>");
                str.push("</tr>");

                $(".table tbody").html(str.join(" "));
                if (loginUser.roleName == "大区经理")
                    $(".area").show();
            }
        );
    }
    initReprot(exhibitionId);

    $(".select2").select2();
</script>
</html>